<!DOCTYPE html>
<html>
<!--
author:guojunyu
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="/static/css/login_reglogin.css"/>
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
        <title>登陆</title>
</head>
<body>
	<div class="bg">
		<img src="/static/images/b.jpg" alt="">
	</div>
	<div class="main">
		<div class="header" >
			<h1>Login!</h1>
		</div>
		<p></p>
			<ul class="right-form">
				<h2>Login:</h2>
				<li><input type="text" class="username" name="username" placeholder="Username" required/></li>
				<li><input type="password" class="password" name="password" placeholder="Password" required/></li>
				<input type="button" value="登录" onclick="login()">
				<div class="clear"> </div>
			</ul>
			<div class="clear"> </div>
	</div>
	
</body>

<script>
	function login() {

		var username = $('.username').val();
		var password = $('.password').val();
		var post_data = {"username":username, "password":password};

		$.ajax({
			type:'post',
			contentType:'application/json',
			dataType:'json',
			data: JSON.stringify(post_data),
			url:'http://127.0.0.1:8000/v1/tokens',
			success: function (result) {
				if (result.code == 200){
					window.localStorage.setItem('dnblog_token',result.data.token);
					window.localStorage.setItem('dnblog_user', result.username);
					alert('登录成功')
				}else{
					alert(result.error)
				}
			}
		})
	}



</script>





</html>
